<?
	if(isQQBrowser() == 'QQ' || isWeixin() == 'MicroMessenger'){ // QQ内置浏览器 或 微信内置浏览器
		echo "<script>alert('请点击页面右上角\"···\"然后选择\"在浏览器打开\"下载电子证书!')</script>";
	} else { // 其他浏览器
		downloadfile(); // 下载文件
	}
	
	function isWeixin(){ 
	   if(strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
	     return true;    //微信内置浏览器
	   } 
	     return false;
	}
	
	function isQQBrowser(){
		if(strpos($_SERVER['HTTP_USER_AGENT'], 'QQ') !== false){  
			if(strpos($_SERVER['HTTP_USER_AGENT'], '_SQ_') !== false){
				return "QQ";  //QQ内置浏览器
			}else{
				return "QQBrowser";  //QQ浏览器
			}
		}
		return false;
	}
	
	function downloadfile () {
		header("Content-Type: application/octet-stream");
	
		$file = $_GET["file"];
		header("Content-Disposition: attachment; filename=" . urlencode($file));   
		header("Content-Type: application/octet-stream");
		header("Content-Type: application/download");
		header("Content-Description: File Transfer");            
		header("Content-Length: " . filesize($file));
		flush(); // 这并不重要.
		$fp = fopen($file, "r");
		while (!feof($fp))
		{
			echo fread($fp, 65536);
			flush(); // 这对于大型文件下载至关重要
		} 
		fclose($fp);
	}
